Computer program developers often create a source design for a given programming project. A source design embodies source code which provides a computer or other electronic device with instructions for achieving desired functionality. The source code may be provided in a number of source languages, including but not limited to C++, Java, HDL, or a graphical language provided in a graphical programming environment, such as Simulink™ from the Mathworks, Inc. of Natick, Mass.
In some circumstances, the source design may contain code written in more than one language. This may occur, for example, if the code is governed by one or more preprocessor directives. A preprocessor directive is an instruction in a preprocessing language that controls whether portions of the source design are compiled. Preprocessor directives may be inserted into the source code for a number of reasons, such as when the source code includes a number of alternative implementations that may be set at compile-time.
When the source code is compiled, the source code is first passed to a preprocessor language engine. The preprocessor language engine parses the source code to identify preprocessor directives and then evaluates the directives to determine whether different segments of the source code should be compiled. Each preprocessor directive may include a condition. When the condition is satisfied, the portion of source code controlled by the preprocessor directive may become active.
For example, C source code may include preprocessor directives preceded by a ‘#’ sign, as in the exemplary source code below:
#if A==1
call_routine1(var1);
#else
call_routine2(var1);
#endif
In the example, above, the preprocessor language engine may evaluate the value of the variable “A”. “A” may be, for example, an environmental variable. If the value of “A” is “1”, the preprocessor language engine inserts the line “call_routine1(var1);” into the source code at the point in the source code where the preprocessor directive was encountered. If the value of “A” is not “1,” then the preprocessor language engine inserts the line “call_routine2(var1);” into the source code at the point that the preprocessor directive was encountered. This means, for example that if A==1 is true, then the C compiler receives “call_rountine1(var1);” but not “call_routine2(var1);”.
Once the preprocessor language engine has identified and processed the preprocessor directives present in the source code, the preprocessor language engine sends the modified source code to a compiler for compilation.